package fr.umlv.escape_ig.ship;

import fr.umlv.escape_ig.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.DisplayMetrics;

/**
 * This class is a singleton. It manages the player's life.
 */
public class Life {
	static class InternLife {
		public static final Life instance = new Life(5, context);

	}

	private int life;
	public final Bitmap heart;
	private static Context context;

	/**
	 * Constructor
	 */
	public Life(int nbLife, Context context) {
		this.life = nbLife;
		heart = BitmapFactory.decodeResource(context.getResources(),
				R.drawable.heart);
	}

	/**
	 * @return instance
	 */
	public static Life getInstance() {
		return InternLife.instance;
	}

	/**
	 * 
	 * @return the number of living
	 */
	public int getLife() {
		return this.life;
	}

	/**
	 * Adds one life. In case of bonus, for example
	 */
	public void moreOne() {
		life++;
	}

	/**
	 * Reduces life of one.
	 */
	public void lessOne() {
		life--;
	}

	/**
	 * Displays the number of cores corresponding to the number of lives
	 * 
	 * @param graphics
	 */

	public void display(DisplayMetrics ecran, Canvas canvas) {

		for (int i = 0; i <= getLife(); i++) {
			canvas.save();
			canvas.drawBitmap(heart, ecran.widthPixels - (heart.getWidth() * i), 0, null);
			canvas.restore();
		}
	}
}
